package
{
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.MouseEvent;

public class HoleTool extends MoveTool
{
	private var focusHole:Hole;
	private var dx:Number;
	private var dy:Number;
	private var focusPoint:Object;
	private var resetting:Boolean;
	
	public function HoleTool()
	{
		super();
		this.keyCode=79;
	}
	
	override public function drawSelectedPoint(point:Object,point_pen:Graphics,mouse_mc:Sprite):void{
		if(!point.isHole)return;
		//is selected
		super.drawSelectedPoint(point,point_pen,mouse_mc);
		
		//draw handler for rect setting
		var handler:Sprite=new Sprite();
		handler.graphics.lineStyle(0,0x0066cc,0);
		handler.graphics.beginFill(0x0066cc,1);
		handler.graphics.drawCircle(0,0,5);
		handler.graphics.endFill();
		
		focusHole=canvas.getHole(point);
		
		
		handler.x=point.x+focusHole.r;
		handler.y=point.y;
		
		
		focusPoint=point;
		
		handler.addEventListener(MouseEvent.MOUSE_DOWN,downHandler);
		mouse_mc.addChild(handler);
		
	}
	
	public function downHandler(evt:MouseEvent):void{
		caughtDown=true;
		resetting=true;
		canvas.stage.addEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
		canvas.stage.addEventListener(MouseEvent.MOUSE_UP,upHandler);
	}
	
	public function upHandler(evt:MouseEvent):void{
		caughtDown=false;
		resetting=false;
		canvas.stage.removeEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
		canvas.stage.removeEventListener(MouseEvent.MOUSE_UP,upHandler);
	}
	
	public function moveHandler(evt:MouseEvent):void{
		var p:Object=canvas.simpleMousePoint();
		focusHole.r=p.x-focusPoint.x;
	}
	
	override public function upOnSpaceWithNoDrag():void{
		trace("create hole:"+canvas.selection.getLength());
		if(canvas.selection.getLength()!=0)return;
		var p:Object=canvas.mousePoint();
		p.r=10;

		//change here to add other things
		canvas.addHole(p);
	}
	/*
	override public function move():void{
		if(target){
			var p:Object=canvas.mousePoint();
			target.x=p.x;
			target.y=p.y;
		}
	}
	*/
	
}

}

